package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.handler.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQueryParam;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

@Api(tags = "车辆管理")
@RestController
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    private VehicleService vehicleService;
    @ApiOperation(value = "查询车辆")
    @ApiImplicitParam(name = "vehicleQuery",value = "车辆查询参数",required = true)
    @GetMapping("/select")
    public JsonResult selectVehicle(VehicleQueryParam vehicleQuery){
        return new JsonResult(vehicleService.selectVehicle(vehicleQuery));
    }
    @ApiOperation(value = "添加车辆")
    @ApiImplicitParam(name = "vehicle",value = "车辆信息",required = true)
    @PostMapping("/save")
    public JsonResult saveVehicle(VehicleSaveParam vehicle){
        vehicleService.saveVehicle(vehicle);
        return JsonResult.ok();
    }
    @ApiOperation(value = "更新车辆")
    @ApiImplicitParam(name = "vehicle",value = "车辆信息",required = true)
    @PostMapping("/update")
    public JsonResult updateVehicle(VehicleSaveParam vehicle){
        vehicleService.updateVehicle(vehicle);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除车辆")
    @ApiImplicitParam(name = "id",value = "车辆id",required = true)
    @DeleteMapping ("/delete/{id}")
    public JsonResult deleteVehicle(@PathVariable("id") Long id){
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "解绑车辆")
    @ApiImplicitParam(name = "geofenceId",value = "电子围栏id",required = true)
    @PutMapping("/bind/{id}/{bindStatus}/{geofenceId}")
    public JsonResult updateBindStatus(
            @PathVariable("id") Long id,
            @PathVariable("bindStatus") String bindStatus,
            @PathVariable("geofenceId") Long geofenceId){
        System.out.println("id="+id+";bindStatus="+bindStatus+";geofenceId="+geofenceId);
        vehicleService.updateBindStatus(id,bindStatus,geofenceId);
        return JsonResult.ok();
    }
}
